﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace Himp.Platform.Api
{
    public class WorkspaceConfService : ApiAppService, IWorkspaceConfService
    {
        private readonly IRepository<WorkspaceConf, Guid> _workspaceConfRepository;

        public WorkspaceConfService(IRepository<WorkspaceConf, Guid> workspaceConfRepository)
        {
            _workspaceConfRepository = workspaceConfRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<WorkspaceConfDto>> GetListAsync(WorkspaceConfInput input)
        {
            var iQuery = await _workspaceConfRepository.GetQueryableAsync();
            iQuery = iQuery.WhereIf(!string.IsNullOrWhiteSpace(input.WorkspaceCodg), i => i.WorkspaceCodg == input.WorkspaceCodg);
            var itemsDto = ObjectMapper.Map<List<WorkspaceConf>, List<WorkspaceConfDto>>(iQuery.ToList());

            return new PagedResultDto<WorkspaceConfDto>(itemsDto.Count, itemsDto);
        }
    }
}